export default {
	//数据
	data() {
		return {
			fatherIndex: 0, //一级菜单默认index
			childIndex: 0, //二级级菜单默认index
			loginShow: true, //登录条默认显示
			userShow: false, //用户信息默认隐藏
			portalConfigList: [], //门户列信息
			portalMainImgUrl: "", //门户主图
			portalSecondImgUrl: "", //门户次图
			requrstData: {
				token: this.get("token"), //token
				userRole: this.get("role"), //角色信息
				userInfo: this.get("userInfo"), //用户信息
				data: null
			}, //接口参数
			/*菜单列表*/
			items: [{
					id: "1",
					name: '首页',
					isSubShow: false,
					path: "index"
				},
				{
					id: "2",
					name: '相关政策',
					isSubShow: false,
					path: "",
					subItems: [{
						name: '国家政策',
						path: "nationalPolicy"
					}, {
						name: '地方政策',
						path: "localPolicy"
					}]
				},
				{
					id: "3",
					name: '资料下载',
					isSubShow: false,
					path: "dataDownload",
				},
				{
					id: "4",
					name: '专家展示',
					isSubShow: false,
					path: "expertsShow"
				},
				{
					id: "5",
					name: '关于我们',
					isSubShow: false,
					path: "aboutUs"
				},
			],

		}
	},
	created() { //调用方法
		
		let that = this;
		//判断用户是否登录
		if(this.requrstData.token != null && this.requrstData.token != "") {
			this.loginShow = false;
			this.userShow = true;
		}
		//初始化友情连接信息
		that.$post(
				that.urls.getAllPortalConfigList, {
					"type": 1
				}
			)
			.then(function(res) {
				if(res.success) {
					that.portalConfigList = res.data;
				}
			})

		//初始化门户图片信息
		that.$post(
				that.urls.getAllPortalConfigList, {
					"type": 0
				}
			)
			.then(function(res) {
				if(res.success) {
					let portalConfigList = res.data;
					for(let i = 0, len = portalConfigList.length; i < len; i++) {
						if(portalConfigList[i].baseType == 0) {
							that.portalMainImgUrl = portalConfigList[i].url; //门户主图
						} else if(portalConfigList[i].baseType == 1) {
							that.portalSecondImgUrl = portalConfigList[i].url; //门户次图
						}
					}
				}
			})
	},
	mounted() {
		
		// 内容版块获取浏览器尺寸
//		var autoDivHeight = document.getElementById('section');
//		var deviceHeight = document.documentElement.clientHeight;
//		autoDivHeight.style.height = (Number(deviceHeight) - 120) + 'px'; //数字是页面布局高度差
	},
	updated:function(){
		if(this.getParamValue("fatherIndex")){
			this.fatherIndex=this.getParamValue("fatherIndex");
		}
	},
	methods: { //写函数方法
		//跳转到管理中心
		goManagementCenter:function(){
			let that = this;
			that.$post(
				that.urls.findMenuByRole, {
					roleId: that.get("userRole") != null ? that.get("userRole").id : null,
					Authorization: that.token
				}
			)
			.then(function(res) {
				if(res.success) {
					that.items = res.data;
					if(that.items.length){
						window.location="/#/"+that.items[0].url+"?fatherIndex=0";
					}else{
						layer.msg('管理中心无菜单', {
							time: 3000, //3s后自动关闭
						});
					}
				   
				} else {
					layer.alert(res.message);
				}
			})
			.catch(function(err) {
				if(err.response) {
					console.log(err.response)
					//控制台打印错误返回的内容
					layer.msg('失败！', {
						time: 3000, //3s后自动关闭
					});
				}
			})
		},
		//用户下拉信息鼠标事件
		showUl: function() {
			$(".wkp-right>div>ul").css("display", "block");
		},
		leaveDiv: function() {
			$(".wkp-right>div>ul").css("display", "none");
		},
		/*菜单切换*/
		showToggle: function(ind, item) {
			this.fatherIndex = ind;
			if(item.subItems){
				this.$router.push({
					path: item.subItems[0].path+"?fatherIndex="+ind+"&childIndex=0"
				})
			}else{
				this.$router.push({
					path: item.path+"?fatherIndex="+ind
				})
			}
			

		},
		clickChild: function(ind,inds, subItem) {
			this.childIndex = inds;
			this.$router.push({
				path: subItem.path+"?fatherIndex="+ind+"&childIndex="+inds
			})
		},
		//跳转到登录页面
		gotoIndex: function() {
		  this.$router.push({
			path: "index",
		  })
		},
		//退出登录
		logOut: function() {
			var that = this;
			that.clear(); //token
			that.$router.push({
				path: "login",
			})
			that.loginShow = true;
			that.userShow = false;
		},

	}
}
